package com.netty.client;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

import com.netty.client.handler.ClientTimeOutHandler;

/**
 * 类说明
 * 
 * @author chenhuaiao
 * @version V1.0 创建时间：Mar 19, 2015 4:43:37 PM
 */
public class ClientChannelInitializer extends ChannelInitializer<Channel> {
	@Override
	public void initChannel(Channel channel) {
		// 禁止缓存类加载器
		channel.pipeline().addLast(
				new ObjectDecoder(1024 * 1024, ClassResolvers
						.weakCachingConcurrentResolver(this.getClass()
								.getClassLoader())));
		// 设置发送消息编码器
		channel.pipeline().addLast(new ObjectEncoder());
		// handler控制逻辑处理
		ClientTimeOutHandler timeoutHandler = new ClientTimeOutHandler();
		channel.pipeline().addLast("clientTimeOutHandler", timeoutHandler);
	}
}
